<?php
/**
 * Created by zengxianfen on 2020/7/23 15:02.
 */

namespace App\Amqp\Builder;


use Hyperf\Amqp\Builder\Builder;
use Hyperf\Amqp\Builder\QueueBuilder;

class AmqpBuilder extends QueueBuilder
{

    /**
     *
     * @author zengxianfen 2020/7/23
     * @param array|\PhpAmqpLib\Wire\AMQPTable $arguments
     * @return Builder
     */
    public function setArguments($arguments): Builder
    {
       $this->arguments = array_merge($this->arguments, $arguments);
       return $this;
    }


    /**
     * @author zengxianfen 2020/7/23
     * @param string $queueName
     * @param int $xMessageTtl
     * @param string $xDeadLetterExchange
     * @param string $xDeadLetterRoutingKey
     * @return AmqpBuilder
     */
    public function setDelayedQueue(string $queueName, int $xMessageTtl, string $xDeadLetterExchange, string $xDeadLetterRoutingKey) : self
    {
        $this->setArguments([
            'x-message-ttl'             => ['I', $xMessageTtl * 1000], // 毫秒
            'x-dead-letter-exchange'    => ['S', $xDeadLetterExchange],
            'x-dead-letter-routing-key' => ['S', $xDeadLetterRoutingKey]
        ]);
        $this->setQueue($queueName);
        return $this;
    }
}